package com.iot.device.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iot.common.annotation.Log;
import com.iot.common.core.controller.BaseController;
import com.iot.common.core.domain.AjaxResult;
import com.iot.common.enums.BusinessType;
import com.iot.device.domain.DeviceSerialNo;
import com.iot.device.service.IDeviceSerialNoService;
import com.iot.common.utils.poi.ExcelUtil;
import com.iot.common.core.page.TableDataInfo;

/**
 * 设备序列号生成Controller
 *
 * @author iot
 * @date 2023-06-12
 */
@RestController
@RequestMapping("/device/deviceSerialNo")
public class DeviceSerialNoController extends BaseController
{
    @Autowired
    private IDeviceSerialNoService deviceSerialNoService;

    /**
     * 查询设备序列号生成列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceSerialNo:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceSerialNo deviceSerialNo)
    {
        startPage();
        List<DeviceSerialNo> list = deviceSerialNoService.selectDeviceSerialNoList(deviceSerialNo);
        return getDataTable(list);
    }

    /**
     * 导出设备序列号生成列表
     */
    @PreAuthorize("@ss.hasPermi('device:deviceSerialNo:export')")
    @Log(title = "设备序列号生成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceSerialNo deviceSerialNo)
    {
        List<DeviceSerialNo> list = deviceSerialNoService.selectDeviceSerialNoList(deviceSerialNo);
        ExcelUtil<DeviceSerialNo> util = new ExcelUtil<DeviceSerialNo>(DeviceSerialNo.class);
        util.exportExcel(response, list, "设备序列号生成数据");
    }

    /**
     * 获取设备序列号生成详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:deviceSerialNo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(deviceSerialNoService.selectDeviceSerialNoById(id));
    }

    /**
     * 新增设备序列号生成
     */
    @PreAuthorize("@ss.hasPermi('device:deviceSerialNo:add')")
    @Log(title = "设备序列号生成", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceSerialNo deviceSerialNo)
    {
        return toAjax(deviceSerialNoService.insertDeviceSerialNo(deviceSerialNo));
    }

    /**
     * 修改设备序列号生成
     */
    @PreAuthorize("@ss.hasPermi('device:deviceSerialNo:edit')")
    @Log(title = "设备序列号生成", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceSerialNo deviceSerialNo)
    {
        return toAjax(deviceSerialNoService.updateDeviceSerialNo(deviceSerialNo));
    }

    /**
     * 删除设备序列号生成
     */
    @PreAuthorize("@ss.hasPermi('device:deviceSerialNo:remove')")
    @Log(title = "设备序列号生成", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(deviceSerialNoService.deleteDeviceSerialNoByIds(ids));
    }
}
